package com.doge.walknovel.business.home.discover.viewholders

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doge.walknovel.api.model.BannerInfo
import com.doge.walknovel.business.home.discover.BANNER
import com.doge.walknovel.core.base.adapters.AdapterCallback
import com.doge.wnpro.databinding.CellDiscoverBannerBinding

class DiscoverBannerViewHolder(
    parent: ViewGroup,
    callback: AdapterCallback,
    private val binding: CellDiscoverBannerBinding = CellDiscoverBannerBinding.inflate(
        LayoutInflater.from(parent.context), parent, false),
) : RecyclerView.ViewHolder(binding.root) {
    init {
        binding.indicator.attach(binding.banner)
        binding.banner.setListener {
            callback.invoke(BANNER, it)
        }
    }

    fun bind(item: List<BannerInfo>) {
        itemView.tag = item
        binding.banner.set(item) { it.url }
        binding.indicator.set(item.size)
        binding.indicator.attach(binding.banner)
    }
}